<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript" src="/js/md5.js"></script>
<script>

__rqs = new __requests();
function __ajax(url, callback, data, dataType, type)
{
    alert(__rqs);
    return false;
    data     = data || {};
    dataType = dataType || 'text';
    type     = type || 'GET';

    // 产生URL KEY
    key = hex_md5(url + data);

    if (!__rqs.check(key)) {
        alert("return false");
        return false;
    }

    // 没有请求过
    $.ajax({
        type: type,
        url: url,
        data: data,
        dataType: dataType,
        success: function(response){
            // 请求成功入口操作
            // 如果统一反回，可以做一起全局错误的弹出，或游戏里面的登出

            alert(response);

            // 请求成功业务操作
            eval(callback + '()');

            // 删除这个请求在在请求的状态
            __rqs.clear(key);

            alert("return true");
        }
    });
}

var __requests = function()
{
    this.__rqs = {},

    // 判断当前请求是存在
    this.check = function(key)
    {
        if (undefined == this.__rqs[key] || '' == this.__rqs[key] || false == this.__rqs[key]) {
            this.__rqs[key] = true;
            return true;
        }
        return false;
    },
    // 请求完成删除
    this.clear = function(key)
    {
        delete this.__rqs[key];
    }
}

function testCallback()
{
    alert('callback');
}
</script>
</head>

<body>
<a href="#" onclick="__ajax('/_sample/ajax/submit', 'testCallback');">AJAX 统一入口 </a>
</body>
</html>